package cn.itcast.demo;
//  通过流对象获取数据
import cn.itcast.bean.Student;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Map;

@WebServlet("/ServletDemo05")
public class ServletDemo05 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.字符流
//        BufferedReader br = req.getReader();
//        String line;
//        while((line = br.readLine())!= null){
//            System.out.println(line);
//        }
//        2.字节流
        ServletInputStream is = req.getInputStream();
        byte[] bytes = new byte[1024];
        int len;
        while ((len = is.read(bytes))!= -1){
            System.out.println(new String(bytes,0,len));
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
